package com.crm.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.crm.dao.FinanceApplyMapper;
import com.crm.dao.SysDutyMapper;
import com.crm.model.FinanceApply;
import com.crm.model.SysDuty;
import com.crm.model.SysUser;
import com.crm.service.FinanceApplyService;
import com.crm.util.SessionModel;
import com.crm.util.SessionUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class FinanceApplyServiceImpl extends BaseServiceImpl<FinanceApply> implements FinanceApplyService {
	@Autowired
	private FinanceApplyMapper financeApplyMapper;
	@Override
	public int insert(FinanceApply record) {
		record.setApplyId(UUID.randomUUID().toString());
		record.setApplicantDate(new Date());
		record.setApplicantStatus(new Byte("0"));
		return super.insert(record);
	}
	@Override
	public int updateByPrimaryKey(FinanceApply record) {
		SysUser sysUser =((SysUser)SessionUtils.get(SessionModel.SESSION_USER));
		record.setModifyDate(new Date());
		record.setModifyUserId(sysUser.getUserId());
		record.setModifyUserName(sysUser.getRealName());
		return super.updateByPrimaryKey(record);
	}
	
	@Override
	public List<FinanceApply> selectAllByWhere(Page<FinanceApply> page,FinanceApply record) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize(), "fa.create_date desc");
		return financeApplyMapper.selectAllByWhere(record);
	}

	@Override
	public int getTotalMoneyByWhere(FinanceApply record) {
		return financeApplyMapper.getTotalMoneyByWhere(record);
	}
	@Override
	public List<FinanceApply> selectAllByWhereContailSelf(Page<FinanceApply> page, FinanceApply record) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize(), "fa.create_date desc");
		return financeApplyMapper.selectAllByWhereContailSelf(record);
	}
	@Override
	public int getTotalMoneyByWhereContailSelf(FinanceApply record) {
		return financeApplyMapper.getTotalMoneyByWhereContailSelf(record);
	}
}
